home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / Standard Catalog Package / DTS AddressOMatic / Src / AddressOMatic.c next >
Encoding:
C/C++ Source or Header  |  1993-06-18  |  8.5 KB  |  363 lines  |  [TEXT/KAHL]

  1. /*                                    AddressOMatic.c                                */
  2. /*
  3.  * AddressOMatic Sample
  4.  * AddressOMatic.c
  5.  * Copyright © 1993 Apple Computer Inc. All rights reserved.
  6.  * AddressOMatic is a Trademark of Apple Computer Inc.
  7.  */
  8. #define _AOM_EXTERN        /* */
  9. #include "AddressOMaticPrivate.h"
  10. #include <OCEStandardMail.h>
  11.  
  12. #define TAB                '\t'
  13.  
  14. /*
  15.  * Create an AddressOMatic panel. If the application disables one of the
  16.  * radio buttons, it should pass NULL or zero for the affected parameter.
  17.  */
  18. pascal OSErr
  19. AOMNewPanel(
  20.         AddressOMaticPtr            *aomPanel,            /* Record stored here    */
  21.         WindowPtr                    window,                /* Put into this window    */
  22.         const Rect                    *bounds,            /* Shape and position    */
  23.         Boolean                        visible,            /* Initially visible    */
  24.         Boolean                        enabled,            /* Initially enabled    */
  25.         AuthIdentity                identity,            /* Initial identity        */
  26.         const RStringPtr            *typesList,            /* Types to select        */
  27.         unsigned long                typeCount,            /* Number of types        */
  28.         void                        *refCon,            /* App owns this value    */
  29.         AOMModeMask                    enableModeMask,        /* What can user do?    */
  30.         AOMModeBit                    initialMode,        /* Starting with?        */
  31.         short                        stringsResID,        /* Labelling strings    */
  32.         short                        browserHelpStringID, /* Browser help string    */
  33.         short                        pdHelpStringID,        /* Personal Cat. help    */
  34.         short                        findHelpStringID,    /* Find panel help        */
  35.         /*
  36.          * The following parameters configure the SDPPanel and Personal Directory
  37.          * Browser.
  38.          */
  39.         const PackedRLI                *initialRLI,        /* Initially selected    */
  40.         DirEnumChoices                enumFlags,            /* Enumeration flags    */
  41.         DirMatchWith                matchTypeHow,        /* Enumeration mode        */
  42.         /*
  43.          * The following parameter configures the SDPFindPanel. Focus is always
  44.          * initially in the text area.
  45.          */
  46.         short                        simultaneousSearchCount
  47. #ifdef ENABLE_TYPEIN
  48.         ,
  49.         /*
  50.          * The following parameter configures the TypeIn callback
  51.          */
  52.         const RStringPtr            typeInRecordType    /* What does it return    */
  53. #endif
  54.     )
  55. {
  56.  
  57.         OSErr                        status;
  58.         register AddressOMaticPtr    aomPtr;
  59.         AOMSaveState                saveState;
  60.         
  61.         aomPtr = (AddressOMaticPtr) NewPtrClear(sizeof (AddressOMaticRecord));
  62.         status = MemError();
  63.         *aomPanel = aomPtr;                                /* NULL on errors        */
  64.         if (aomPtr == NULL || status != noErr)
  65.             goto exit;
  66.         /*
  67.          * Copy user parameters into the AOM record.
  68.          */
  69.         AOM.window = window;
  70.         _AOMSaveState(aomPtr, kAOMLabelFontStyle, &saveState);
  71.         BOUNDS = *bounds;                                /* Location and size    */
  72.         AOM.isVisible = visible;
  73.         AOM.isEnabled = enabled;
  74.         AOM.identity = identity;
  75.         AOM.typesList = typesList;
  76.         AOM.typeCount = typeCount;
  77.         AOM.refCon = refCon;
  78.         AOM.currentMode = kAOMUnknownMode;
  79.         /*
  80.          * Lie about the state of the buttons so they will be
  81.          * disabled when we finish creating the panels.
  82.          */
  83.         AOM.enableToButton = TRUE;
  84.         AOM.enableCCButton = TRUE;
  85.         AOM.stringsResID = stringsResID;
  86. #ifdef ENABLE_TYPEIN
  87.         AOM.typeInRecordType = typeInRecordType;
  88. #endif
  89.         EraseRect(&BOUNDS);
  90.         status = _AOMCreateButtons(aomPtr, enableModeMask);
  91.         _AOMDecorateDisplay(aomPtr);
  92.         AOMUpdatePanel(aomPtr, NULL);
  93.         ValidRect(&BOUNDS);
  94.         _AOMSetFont(aomPtr, kAOMTextFontStyle);    /* Not bold    */
  95.         enumFlags &= ~kEnumInvisibleMask;
  96.         if (status == noErr
  97.          && (enableModeMask & kAOMEnablePDMask) != 0) {
  98.             status = _AOMPanelCreate(
  99.                         aomPtr,
  100.                         typesList,
  101.                         typeCount,
  102.                         (PackedRLI *) -1,
  103.                         enumFlags,
  104.                         matchTypeHow,
  105.                         pdHelpStringID,
  106.                         &AOM.pdPanel
  107.                     );
  108.         }
  109.         if (status == noErr
  110.          && (enableModeMask & kAOMEnablePanelMask) != 0) {
  111.             status = _AOMPanelCreate(
  112.                         aomPtr,
  113.                         typesList,
  114.                         typeCount,
  115.                         initialRLI,
  116.                         enumFlags,
  117.                         matchTypeHow,
  118.                         browserHelpStringID,
  119.                         &AOM.browsePanel
  120.                     );
  121.         }
  122.         if (status == noErr
  123.          && (enableModeMask & kAOMEnableFindMask) != 0) {
  124.             status = _AOMFindCreate(
  125.                         aomPtr,
  126.                         typesList,
  127.                         typeCount,
  128.                         simultaneousSearchCount,
  129.                         kSDPFindPanelTextHasFocus,
  130.                         matchTypeHow,
  131.                         findHelpStringID
  132.                     );
  133.         }
  134. #ifdef ENABLE_TYPEIN
  135.         if (status == noErr
  136.          && (enableModeMask & kAOMEnableTypeInMask) != 0) {
  137.             status = _AOMTypeInCreate(aomPtr);
  138.         }
  139. #endif
  140.         _AOMSetFont(aomPtr, kAOMLabelFontStyle);
  141.         if (status == noErr) {
  142. #ifdef kFirstSpinnerIcon                /* Not in Beta 1    */
  143.             AOM.animationSICNIndex = kFirstSpinnerIcon;
  144.             AOM.nextAnimation = TickCount() + kSpinnerDelay;
  145. #endif
  146.         }
  147.         if (status == noErr) {
  148.             _AOMSelectMode(aomPtr, initialMode);
  149.             _AOMPlotIcon(aomPtr, initialMode, TRUE);
  150.             _AOMSetButtonText(aomPtr);
  151.         }
  152.         else {
  153.             (void) AOMDisposePanel(aomPtr);
  154.             *aomPanel = NULL;
  155.         }
  156.         _AOMRestoreState(&saveState);
  157. exit:    LOG(status, "\pAOMNewPanel exit");
  158.         return (status);
  159. }
  160.  
  161. /*
  162.  * Clean up the mess.
  163.  */
  164. pascal OSErr
  165. AOMDisposePanel(
  166.         AddressOMaticPtr            aomPtr                /* The panel            */
  167.     )
  168. {
  169.         OSErr                        status;
  170.         OSErr                        returnStatus;
  171.         
  172.         returnStatus = status = noErr;
  173.         if (aomPtr != NULL) {
  174.             if (AOM.pdPanel != NULL)
  175.                 status = returnStatus = _AOMPanelDispose(aomPtr, AOM.pdPanel);
  176.             if (AOM.browsePanel != NULL) {
  177.                 status = _AOMPanelDispose(aomPtr, AOM.browsePanel);
  178.                 if (returnStatus == noErr)
  179.                     returnStatus = status;
  180.             }
  181.             if (AOM.findPanel != NULL) {
  182.                 status = _AOMFindDispose(aomPtr);
  183.                 if (returnStatus == noErr)
  184.                     returnStatus = status;
  185.             }
  186. #ifdef ENABLE_TYPEIN
  187.             status = _AOMTypeInDispose(aomPtr);
  188.             if (returnStatus == noErr)
  189.                 returnStatus = status;
  190. #endif
  191.             if (AOM.doneButton != NULL)
  192.                 DisposeControl(AOM.doneButton);
  193.             if (AOM.ccButton != NULL)
  194.                 DisposeControl(AOM.ccButton);
  195.             if (AOM.toButton != NULL)
  196.                 DisposeControl(AOM.toButton);
  197.             DisposePtr((Ptr) aomPtr);
  198.         }
  199.         return  (returnStatus);
  200. }
  201.  
  202. /*
  203.  * Return the panel's minimum sizes.
  204.  */
  205. void
  206. AOMGetDimensions(
  207.         short                        *minimumWidth,
  208.         short                        *minimumHeight
  209.     )
  210. {
  211.         *minimumWidth = kAOMWidthMinimum;
  212.         *minimumHeight = kAOMHeightMinimum;
  213. }
  214.  
  215. /*
  216.  * Move and resize in one big lump.
  217.  */
  218. pascal OSErr
  219. AOMAdjustPanel(
  220.         AddressOMaticPtr            aomPtr,
  221.         const Rect                    *boundsRect
  222.     )
  223. {
  224.         InvalRect(&BOUNDS);
  225.         BOUNDS = *boundsRect;
  226.         _AOMDecorateDisplay(aomPtr);
  227.         InvalRect(&BOUNDS);
  228.         return (noErr);
  229. }
  230.  
  231. pascal OSErr
  232. AOMExtractSelection(
  233.         AddressOMaticPtr            aomPtr,
  234.         unsigned short                *selectionSize,
  235.         PackedDSSpecPtr                *selection
  236.     )
  237. {
  238.         OSErr                        status;
  239.         
  240.         switch (AOM.currentMode) {
  241.         case kAOMEnablePDBit:
  242.             status = _AOMPanelExtractSelection(
  243.                         aomPtr,
  244.                         AOM.pdPanel,
  245.                         selectionSize,
  246.                         selection
  247.                     );
  248.             break;
  249.         case kAOMEnablePanelBit:
  250.             status = _AOMPanelExtractSelection(
  251.                         aomPtr,
  252.                         AOM.browsePanel,
  253.                         selectionSize,
  254.                         selection
  255.                     );
  256.             break;
  257.         case kAOMEnableFindBit:
  258.             status = _AOMFindExtractSelection(
  259.                         aomPtr,
  260.                         selectionSize,
  261.                         selection
  262.                     );
  263.             break;
  264. #ifdef ENABLE_TYPEIN
  265.         case kAOMEnableTypeInBit:
  266.             status = _AOMTypeInExtractSelection(
  267.                         aomPtr,
  268.                         selectionSize,
  269.                         selection
  270.                     );
  271.             break;
  272. #endif
  273.         }
  274.         return (status);
  275. }
  276.  
  277.  
  278.  
  279. /*
  280.  * This should be done by using the identity queue instead.
  281.  */
  282. pascal OSErr
  283. AOMSetIdentity(
  284.         AddressOMaticPtr            aomPtr,                /* The panel            */
  285.         AuthIdentity                userIdentity
  286.     )
  287. {
  288.         OSErr                        status;
  289.         OSErr                        result;
  290.         
  291.         result = _AOMPanelSetIdentity(aomPtr, AOM.browsePanel, userIdentity);
  292.         status = _AOMPanelSetIdentity(aomPtr, AOM.pdPanel, userIdentity);
  293.         if (result == noErr)
  294.             result = status;
  295.         status = _AOMFindSetIdentity(aomPtr, userIdentity);
  296.         if (result == noErr)
  297.             result = status;
  298.         /* Type-in ignores identity? */
  299.         return (result);
  300. }
  301.  
  302. void
  303. _AOMSaveState(
  304.         register AddressOMaticPtr    aomPtr,
  305.         AOMFontStyle                textFace,
  306.         register AOMSaveStatePtr    statePtr
  307.     )
  308. {
  309. #define STATE    (*statePtr)
  310.  
  311.         GetPort(&STATE.savePort);
  312.         SetPort(AOM.window);
  313.         GetPenState(&STATE.savePenState);
  314.         STATE.textFont = qd.thePort->txFont;
  315.         STATE.textSize = qd.thePort->txSize;
  316.         STATE.textFace = qd.thePort->txFace;
  317.         if (IS_COLOR(AOM.window)) {
  318.             GetForeColor(&STATE.foregroundColor);
  319.             GetBackColor(&STATE.backgroundColor);
  320.         }
  321.         _AOMSetFont(aomPtr, textFace);
  322. #undef STATE
  323. }
  324.  
  325. void
  326. _AOMSetFont(
  327.         register AddressOMaticPtr    aomPtr,
  328.         AOMFontStyle                textFace
  329.     )
  330. {
  331.         if (IS_COLOR(AOM.window)) {
  332.             RGBBackColor(
  333.                 (textFace == kAOMLabelFontStyle)
  334.                     ? &_AOMBackgroundColor
  335.                     : &_AOMWhiteColor
  336.             );
  337.             RGBForeColor(&_AOMBlackColor);
  338.         }
  339.         PenNormal();
  340.         TextFont(kAOMLabelFontNumber);
  341.         TextSize(kAOMLabelFontSize);
  342.         TextFace(textFace);
  343. }
  344.  
  345. void
  346. _AOMRestoreState(
  347.         register AOMSaveStatePtr    statePtr
  348.     )
  349. {
  350. #define STATE    (*statePtr)
  351.  
  352.         TextFont(STATE.textFont);
  353.         TextSize(STATE.textSize);
  354.         TextFace(STATE.textFace);
  355.         if (IS_COLOR(qd.thePort)) {
  356.             RGBBackColor(&STATE.backgroundColor);
  357.             RGBForeColor(&STATE.foregroundColor);
  358.         }
  359.         SetPenState(&STATE.savePenState);
  360.         SetPort(STATE.savePort);
  361. #undef STATE
  362. }
  363.